package top.dingyingying.springboot3.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.dingyingying.springboot3.base.PageBean;
import top.dingyingying.springboot3.base.R;
import top.dingyingying.springboot3.entity.TbStudent;
import top.dingyingying.springboot3.service.TbStudentService;
import top.dingyingying.springboot3.vo.PageVo;

@RestController
@RequiredArgsConstructor
@RequestMapping("/student")
public class TbStudentController {
    private final TbStudentService tbStudentService;


    @PostMapping("")
    public R<String> insert(@RequestBody TbStudent tbStudent) {
        return tbStudentService.insert(tbStudent);
    }

    //pageNumber第几页  一般为1
//    pageSize页的大小，一页里面有几个数据,一般大于1
    @GetMapping("/{ps}/{pn}")
    public R<PageVo<TbStudent>> query(@PathVariable("ps") Long pageSize, @PathVariable("pn") Long pageNumber, TbStudent tbStudent) {
        return tbStudentService.query(tbStudent, PageBean.instance(pageNumber, pageSize));
    }

    @GetMapping("/{id}")
    public R<TbStudent> queryById(@PathVariable("id") Integer id) {
        return tbStudentService.queryById(id);
    }

@PutMapping("")
    public R<String> update(@RequestBody TbStudent tbStudent) {
        return tbStudentService.update(tbStudent);
    }


    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id) {
        return tbStudentService.delete(id);
    }











}
